package cn.caidabao.gb.component.sip.server.storage;

import cn.caidabao.gb.bean.OGSipCallIdCallBack;
import org.springframework.stereotype.Component;

import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

@Component
public class CallBackStorage {
    private ConcurrentMap<String, OGSipCallIdCallBack> callBackMap = new ConcurrentHashMap();
    private ConcurrentMap<String, OGSipCallIdCallBack> channelCallBackMap = new ConcurrentHashMap<>();

    public void putCallBack(String callId, OGSipCallIdCallBack callBack){
        callBackMap.put(callId,callBack);
        if (callBack.getChannelId()!=null){
            channelCallBackMap.put(callBack.getChannelId(),callBack);
        }
    }

    public OGSipCallIdCallBack getAndDeleteCallBack(String callId){
        OGSipCallIdCallBack ogSipCallBack = callBackMap.get(callId);
        callBackMap.remove(callId);
        return ogSipCallBack;
    }

    public OGSipCallIdCallBack getCallBack(String callId){
        return callBackMap.get(callId);
    }

    public OGSipCallIdCallBack getAndDeleteCallBackByChannelId(String channelId){
        OGSipCallIdCallBack ogSipCallBack = channelCallBackMap.get(channelId);
        channelCallBackMap.remove(channelId);
        return ogSipCallBack;
    }

    public OGSipCallIdCallBack getCallBackByChannelId(String channelId){
        OGSipCallIdCallBack ogSipCallBack = channelCallBackMap.get(channelId);
        return ogSipCallBack;
    }
}
